home *** CD-ROM | disk | FTP | other *** search
- { ========================================================================= }
- { PROGRAM: CLPDemo.Exe - CLParser Demo Program }
- { ========================================================================= }
- { }
- { }
- { !!! ! !!! !!!!!! }
- { ! !! ! ! ! Command Line Parser Unit v3.1 }
- { ! ! ! ! ! }
- { ! ! ! ! !!!! !! !!! !!!!! !!!! !! !!! }
- { ! ! ! ! ! !! ! ! ! ! ! !! ! }
- { ! ! !!!!! !!!!! ! !! !!!!!! ! }
- { ! ! ! ! ! ! ! !! ! ! }
- { ! ! ! ! ! ! ! ! ! ! ! ! ! }
- { !!! !!!!!!! !!! !!!! ! !!! !!!!! !!!! !!! }
- { }
- { Copyright (c) 1991, Greg L. Truesdell }
- { All Rights Reserved }
- { }
- { ========================================================================= }
- Program ClpDemo_v2;
-
- Uses
- DOS, CLParser;
-
- Const
- { NormalChars : Set of Char = [#32..#127]; } { defined in CLParser }
- { Switches : Set of Char = ['/','-','+']; } { defined in CLParser }
- SpecialChars : Set of Char = ['_','&'];
-
- Var
- { object pointers }
- pArg, pSw : pArgument; { arguments / switches }
- pW : pWild; { wild card list }
- pF : pPFile; { parameter file }
- pEnv : pEnviron; { environment list }
-
- { ========================================================================= }
- { D I S P L A Y L I S T }
- { ========================================================================= }
- Procedure DisplayList ( ListObject : pArgument; Message: String );
- var
- i : Integer;
- ta : String;
- Add_OK : Boolean;
-
- begin
-
- { exit if no items in the list }
-
- if ListObject^.Count = 0 then
- EXIT;
-
- { write a header for the list }
-
- WriteLn;
- WriteLn( Message+':' );
- WriteLn( 'Item# Position# Item' );
- WriteLn( '----- --------- ---------------------------------------' );
-
- Add_OK := ListObject^.Add( 'End of '+Message,0 );
-
- for i := 1 to ListObject^.Count do
- begin
-
- ta := ListObject^.Next;
- WriteLn( i:5, ListObject^.Position:10, ' ', ta );
-
- end;
-
- { report if the list was overflowed }
-
- if ListObject^.Overflow then Writeln('Overflow!');
-
- { let us know if the add was not successful }
-
- if not Add_OK then WriteLn( 'Couldn''t add comment!' );
-
- end;
-
- { ========================================================================= }
- { D O D E M O }
- { ========================================================================= }
- Procedure Do_Demo;
- var
- ta : String;
-
- begin
-
- { display the primary lists }
-
- DisplayList( pArg, 'Argument List' );
- DisplayList( pSw, 'Switch List' );
- DisplayList( pEnv, 'Environment List');
-
- { search for a specific item in a list }
-
- if pEnv^.Find('Path=') <> '' then
- begin
-
- WriteLn;
- WriteLn('Found PATH Environment Variable ---');
- WriteLn(' ', pEnv^.Find('path=') );
-
- end;
-
- { Release the current switch list and parse for special switches }
-
- pSw^.Done;
- pSw^.Init( SpecialChars );
- DisplayList( pSw, 'Special List');
-
- { get the volume id }
-
- pW := New( pWild, Init('\*.*',VolumeID));
-
- { if found, display it }
-
- if pW^.Count > 0 then
- begin
-
- ta := pW^.Next;
-
- Delete(ta,9,1); { delete the "." in the filename }
-
- WriteLn;
- WriteLn('Volume ID: ', ta);
-
- end;
-
- { check for _f= switch for file mask ( ie. CLPDEMO _F=*.PAS )}
- { if it is there, use it }
-
- ta := pSw^.Find('_f');
-
- if ta <> ''
- then ta := copy(ta,4,length(ta)-3) { get just the mask }
- else ta := '*.*'; { otherwise assume all files }
-
- { clear the current wild list and parse for new list }
- { fill the list with matching files (not directories or the volume id }
-
- pW^.Done;
- pW^.Init(ta,AnyFile-Directory-VolumeID);
-
- { display the new list }
-
- DisplayList( pW, 'Wildcard List ('+ ta + ')');
-
- { erase the current wild list and parse for directories }
-
- pW^.Done;
- pW^.Init( ta, Directory );
-
- DisplayList( pW, 'Directory List ('+ ta + ')');
- DisplayList( pF, 'Parameter File List (CLPDEMO.DAT)');
-
- end;
-
- { ========================================================================= }
- { I N I T I A L I Z E L I S T S }
- { ========================================================================= }
- { }
- { This procedure initializes the argument list to exclude arguments }
- { starting with special characters. These special characters will be }
- { used later as switch indicators. }
- { }
- { The demo parameter file is loaded into the file list. (CLPDEMO.DAT) }
- { }
- { ========================================================================= }
- Procedure Initialize_Lists;
- begin
-
- { parse for arguments - switches - specials }
-
- pArg := New( pArgument, Init( NormalChars-Switches-SpecialChars ) );
-
- { parse for switches }
-
- pSw := New( pArgument, Init(Switches) );
-
- { fill the environ list }
-
- pEnv := New( pEnviron, Init );
-
- { fill the parameter file list }
-
- pF := New( pPFile, Init( 'CLPDEMO.DAT', [';','*'] ) );
-
- end;
-
- { ========================================================================= }
- { E R A S E L I S T S }
- { ========================================================================= }
- Procedure Erase_Lists;
- begin
-
- Dispose( pSw, Done );
- Dispose( pArg, Done );
- Dispose( pEnv, Done );
- Dispose( pW, Done );
- Dispose( pF, Done );
-
- end;
-
-
- { ========================================================================= }
- { M A I N }
- { ========================================================================= }
- Begin
-
- { turn redirection on }
-
- Assign(Output, ''); Rewrite(Output);
- Assign(Input, ''); Reset(Input);
-
- Initialize_Lists;
-
- Do_Demo;
-
- Erase_Lists;
-
- End.
-
- { ========================================================================= }
- { E O F }
- { ========================================================================= }
-
-